#!/usr/bin/env python3

from launch import LaunchDescription
from launch_ros.actions import Node
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration

def generate_launch_description():
    # 声明启动参数
    camera_id_arg = DeclareLaunchArgument(
        'camera_id',
        default_value='0',
        description='Camera device ID'
    )
    
    frame_width_arg = DeclareLaunchArgument(
        'frame_width',
        default_value='640',
        description='Frame width'
    )
    
    frame_height_arg = DeclareLaunchArgument(
        'frame_height',
        default_value='480',
        description='Frame height'
    )
    
    fps_arg = DeclareLaunchArgument(
        'fps',
        default_value='30',
        description='Frames per second'
    )
    
    show_video_arg = DeclareLaunchArgument(
        'show_video',
        default_value='true',
        description='Show video window'
    )
    
    save_video_arg = DeclareLaunchArgument(
        'save_video',
        default_value='false',
        description='Save processed video'
    )
    
    # 创建摄像头节点
    camera_node = Node(
        package='video_det_camera',
        executable='camera_node',
        name='camera_node',
        parameters=[{
            'camera_id': LaunchConfiguration('camera_id'),
            'frame_width': LaunchConfiguration('frame_width'),
            'frame_height': LaunchConfiguration('frame_height'),
            'fps': LaunchConfiguration('fps'),
        }],
        output='screen',
        emulate_tty=True
    )
    
    # 创建视频检测节点
    video_det_node = Node(
        package='video_det_camera',
        executable='video_det_node',
        name='video_det_node',
        parameters=[{
            'show_video': LaunchConfiguration('show_video'),
            'save_video': LaunchConfiguration('save_video'),
            'output_path': 'output_video.avi',
        }],
        output='screen',
        emulate_tty=True
    )
    
    return LaunchDescription([
        # 启动参数
        camera_id_arg,
        frame_width_arg,
        frame_height_arg,
        fps_arg,
        show_video_arg,
        save_video_arg,
        
        # 节点
        camera_node,
        video_det_node,
    ])
